home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / nihcl-30.lha / nihcl-3.0 / test / date.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  5KB  |  120 lines

  1. /* Test class Date
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    date.c,v $
  26.  * Revision 3.0  90/05/20  00:28:55  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/date.c,v 3.0 90/05/20 00:28:55 kgorlen Rel $";
  31.  
  32. #include <osfcn.h>
  33. #include "Date.h"
  34. #include "SortedCltn.h"
  35.  
  36. main()
  37. {
  38.     cout << "\nTest class Date" << endl;
  39.     char junk[100];
  40.     Date today;
  41.     Date tomorrow(today+1);
  42.     Date yesterday(today-1);
  43.     Date reference(25,"Dec",1985);
  44.     Date ref_copy = reference;
  45.     SortedCltn datelist;
  46.     dayTy   d;
  47.     
  48. //      This portion is to check those functions of Date which only need
  49. //      to be tested once.
  50.     
  51.     cerr << "Today is " << Date::nameOfDay(today.weekDay()) << ", " << today << endl;
  52.     cerr << "Tomorrow is " << Date::nameOfDay(tomorrow.weekDay()) << ", " << tomorrow << endl;
  53.     cerr << "Yesterday was " << Date::nameOfDay(yesterday.weekDay()) << ", " << yesterday << endl;
  54.  
  55.     cout << "Date(5) = "  << Date(5L) << endl;
  56.     cout << "Date(-3) = " << Date(-3L) << endl;
  57.     cout << "Date(367, 1984) = " << Date(367,1984) << endl;
  58.     cout << "Date(-1, 1984) = " << Date(-1,1984) << endl;
  59.     cout << "nameOfMonth(6) = " << Date::nameOfMonth(6) << endl;
  60.  
  61.     cout << "Enter string for dayOfWeek: ";
  62.      cin  >> junk;
  63.     if (cin.eof()) { cout << endl; exit(1); }    
  64.      cout << "dayOfWeek(" << junk << ") = " << Date::dayOfWeek(junk) << endl;
  65.     cout << "Enter string for numberOfMonth: ";
  66.     cin  >> junk;
  67.     if (cin.eof()) { cout << endl; exit(1); }    
  68.      cout << "numberOfMonth(" << junk << ") = " << Date::numberOfMonth(junk) << endl;
  69.     cout << "Enter number for nameOfDay: ";
  70.     cin  >> d;
  71.     if (cin.eof()) { cout << endl; exit(1); }    
  72.      cout << "nameOfDay(" << d << ") = " << Date::nameOfDay(d) << endl;
  73.  
  74.     cout << "Reference date is " << ref_copy << endl;
  75.     cout << "Enter date for scanFrom: ";
  76.     ref_copy.scanFrom(cin);
  77.     cout << "Replaced ref_copy by " << ref_copy << endl;
  78.  
  79. //    Now do the repetitive stuff.
  80.  
  81.     while (YES) {
  82.         cout << "Enter date: "; Date& date = *new Date(cin); cout << endl;
  83.         if (cin.eof()) break;
  84.         if (cin.fail()) { cout << "Bad date" << endl;  cin.clear();  cin.get(junk,sizeof junk);  continue; }
  85.         cout << Date::nameOfDay(date.weekDay()) << ", " << date << endl;
  86.         cout << reference << " - " << date << " = " << (reference-date) << endl;
  87.         cout << date << " between(1-Jan-85, 31-Dec-85): " << (date.between(Date(1,"Jan",85), Date(31,"Dec",85))) << endl;
  88.         cout << date << " max(" << reference << ") = " << date.max(reference) << endl;
  89.         cout << date << " min(" << reference << ") = " << date.min(reference) << endl;
  90.         cout << "The date of the previous Sunday is " << date.previous("Sun") << endl;
  91.         cout << "The date of the previous Thursday is " << date.previous("Thursday") << endl;
  92.         cout << "date.compare(reference) = " << date.compare(reference) << endl;
  93.         cout << "date.day() = "     << date.day()          << endl;
  94.         cout << "date.dayOfMonth() = "       << date.dayOfMonth()       << endl;
  95.         cout << "daysInYear(date.year()) = " << Date::daysInYear(date.year()) << endl;
  96.         cout << "date.firstDayOfMonth() = "  << date.firstDayOfMonth()  << endl;
  97.         cout << "date.hash() = "         << date.hash()        << endl;
  98.         cout << "date.isEqual(reference) = " << date.isEqual(reference)    << endl;
  99.         cout << "this + 50 = "              << date + 50        << endl;
  100.         cout << "50 + this = "             << 50 + date        << endl;
  101.         cout << "this - 60  = "             << date - 60        << endl;
  102.         cout << "this < reference = "         << (date < reference)    << endl;
  103.         cout << "this > reference = "         << (date > reference)    << endl;
  104.         cout << "this <= reference = "         << (date <= reference)    << endl;
  105.         cout << "this >= reference = "         << (date >= reference)    << endl;
  106.         cout << "this == reference = "         << (date == reference)    << endl;
  107.         cout << "this != reference = "         << (date != reference)    << endl;
  108.         Date date1=date;
  109.         date1 += 50;
  110.         cout << "this += 50 = "             << date1            << endl;
  111.         Date date2=date;
  112.         date2 -= 60;
  113.         cout << "this -=60 = "             << date2            << endl;
  114.         datelist.add(date);
  115.         cout << datelist << endl;
  116.  
  117.     } // while(YES)
  118.     cout << endl;    
  119. }
  120.